package com.tianyadu.mmall.core.conf;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.config.annotation.SecurityConfigurerAdapter;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.web.DefaultSecurityFilterChain;
import org.springframework.security.web.authentication.preauth.AbstractPreAuthenticatedProcessingFilter;
import org.springframework.stereotype.Component;

import javax.servlet.Filter;

/**
 * 验证码安全认证配置
 *
 * @author xueyj
 * @date 2019-11-14 23:34
 */
@Component
public class ValidateCodeSecurityConfig extends SecurityConfigurerAdapter<DefaultSecurityFilterChain, HttpSecurity> {

    /**
     * 验证码拦截器
     */
    @Autowired
    private Filter validateCodeFilter;

    /**
     * 将验证码拦截器添加至抽象预认证处理过滤器AbstractPreAuthenticatedProcessingFilter之前
     *
     * @param http HttpSecurity
     * @return void
     * @author xueyj
     * @date 2019/11/14-23:35
     */
    @Override
    public void configure(HttpSecurity http) throws Exception {
        //  添加validateCodeFilter至抽象预认证处理过滤器AbstractPreAuthenticatedProcessingFilter之前
        http.addFilterBefore(validateCodeFilter, AbstractPreAuthenticatedProcessingFilter.class);
    }

}